package luban.Loader;

import com.google.gson.JsonElement;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class JsonResourceLoad implements IJsonLoader{
    private static final String RESOURCE_PATH = "cfg/luban/json/%s.json";
    @Override
    public JsonElement load(String file) throws IOException {
        String resourcePath = RESOURCE_PATH.formatted( file);
        // 读取resource文件
        try (InputStream is = getClass().getClassLoader().getResourceAsStream(resourcePath)) {
            if (is == null) {
                throw new IOException("Resource not found: " + resourcePath);
            }
            return com.google.gson.JsonParser.parseReader(new InputStreamReader(is));
        }
    }
}
